﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Jungle.Code.DAL;

namespace Jungle.Prodamo.PriceManager
{
    public class PBC
    {
        private int producerId;
        private int categoryId;

        List<Producer> ProducerList;

        public int ProducerId { get { return producerId; } set { producerId = value; } }
        public int CategoryId { get { return categoryId; } set { categoryId = value; } }

        public void Add()
        {
            using (SqlConnection connect = new SqlConnection(DBHelper.ConnectionString))
            {
                SqlCommand command = new SqlCommand("ProducersByCategory_Add", connect);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.Add("@ProducerId", SqlDbType.Int).Value = producerId;
                command.Parameters.Add("@CategoryId", SqlDbType.Int).Value = categoryId;

                command.Connection.Open();
                command.ExecuteNonQuery();
                command.Connection.Close();
            }
        }
        public void GetByCategory()
        {
            using (SqlConnection connect = new SqlConnection(DBHelper.ConnectionString))
            {
                ProducerList = new List<Producer>();
                SqlCommand command = new SqlCommand("ProducersByCategory_GetByCategory", connect);
                SqlDataReader reader = null;

                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add("@CategoryId", SqlDbType.Int).Value = categoryId;
                command.Connection.Open();
                reader = command.ExecuteReader();
                while (reader.Read())
                { 
                    Producer pr = new Producer();
                    pr.ProducerId = (int)reader["ProducerId"];
                    pr.GetById();

                    ProducerList.Add(pr);
                }
                reader.Close();
                command.Connection.Close();
            }
        }


    }
}